/*
 * author      : 吴中勤 
 * date        : 2018/9/4
 * description : TODO
 */

package com.deepexi.adapter.rocketmq;

import com.deepexi.adapter.common.ResourceUtils;
import com.deepexi.adapter.facade.moby.request.MobyEventBody;
import com.deepexi.mq.api.IMQService;
import com.deepexi.mq.api.MQFactory;
import com.deepexi.mq.domain.MessageRegistryVo;

import static java.lang.Thread.sleep;

public class MockMobySender {

    private static String tagName = "WORKFLOW";

    public static void main(String[] args) throws InterruptedException {
        send("MOBY_ORDER_DEPOSIT_SUCCESS", "mock/moby/message_120.json");
    }

//        topicSubscribed.add(MOBY_ORDER_DEPOSIT_SUCCESS);
//        topicSubscribed.add(MOBY_DEPOSIT_CONVERT);
//        topicSubscribed.add(MOBY_MAKE_LOAN_SUCCESS);
//        topicSubscribed.add(MOBY_BALANCE_DOWN_PAYMENT);
//        topicSubscribed.add(MOBY_BALANCE_DOWN_COMPLETE);
//        topicSubscribed.add(MOBY_BALANCE_PAY_CONFIRM);
//        topicSubscribed.add(MOBY_UPLOAD_INSURANCE_POLICY);
//        topicSubscribed.add(MOBY_UPLOAD_VOUCHER_SUCCESS);
//        topicSubscribed.add(MOBY_BOUTIQUE_CHANGE);
//        topicSubscribed.add(MOBY_REFUND_DEPOSIT);

//vo.setType("rocket");
//vo.setBrokerList(namesrvAddr);
//vo.setProfile(profile);
//vo.setInstanceName("DEFAULT");

    private static void send(String topicName, String resPath) throws InterruptedException {
        MessageRegistryVo vo = new MessageRegistryVo();

        vo.setType("rocket");
        vo.setBrokerList("118.31.184.251:9876");
        vo.setInstanceName("DEFAULT");
        vo.setGroupName("adapter");
        IMQService mqService = MQFactory.createMQ(vo);

        MobyEventBody body = ResourceUtils.loadRes2Object(resPath, MobyEventBody.class);
        String content = body.uglyString();

        for (int i = 0; i < 100; i++) {
            mqService.createProducer().sendMessage(topicName, tagName, content);
            System.out.println(i + " send topic=" + topicName + ", content=" + content);
            sleep(3000);
        }
    }

}
